package com.guigu.qingcheng.orderservice.controller;

import com.guigu.qingcheng.orderservice.service.CartSerivce;
import com.guigu.qingcheng.utils.R;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.HashMap;
import java.util.List;
import java.util.Map;

@RestController
@RequestMapping("/cart")
public class CartController {

    @Autowired
    private CartSerivce serivce;

    @GetMapping("findCartList")
    public List<Map<String, Object>> findCartList() {
        String usernmae = "覃仁斌";
        List<Map<String, Object>> cartList = serivce.findCartList(usernmae);
        return cartList;
    }

    @GetMapping("addItem")
    public R addItem(String username, String skuId, Integer num) {
        username = "覃仁斌";
        serivce.addItem(username, skuId, num);
        return R.ok();
    }

    /**
     * 更改购物车项选中状态
     *
     * @param skuId
     * @param checked
     * @return
     */
    @GetMapping("updateChecked")
    public void updateChecked(String username, String skuId, boolean checked) {
        serivce.updateChecked(username, skuId, checked);
    }

    /**
     * 删除选中的购物车
     */
    @GetMapping("deleteCheckedCart")
    public R deleteCheckedCart() {
        String username = "覃仁斌";
        serivce.deleteCheckedCart(username);
        return R.ok();
    }

    /**
     * 计算当前选中的购物车的优惠金额
     * @param
     * @return
     */
    @GetMapping("preferential")
    public Map preferential(){
        String username = "覃仁斌";
        int preferential = serivce.preferential(username);
        Map map=new HashMap();
        map.put("preferential",preferential);
        return map;
    }

    /**
     * 获取刷新单价后的购物车列表
     * @return
     */
    @GetMapping("findNewOrderItemList")
    public List<Map<String, Object>> findNewOrderItemList(){
        String username = "覃仁斌";
        return serivce.findNewOrderItemList(username);
    }
}
